package ms.pc.inf;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyCustomBaseAdapter extends BaseAdapter {
	 private static ArrayList<EventInfo> eventList;
	 
	 private LayoutInflater mInflater;

	 public MyCustomBaseAdapter(Context context, ArrayList<EventInfo> results) {
		 eventList = results;
	  mInflater = LayoutInflater.from(context);
	 }

	 public int getCount() {
	  return eventList.size();
	 }

	 public Object getItem(int position) {
	  return eventList.get(position);
	 }

	 public long getItemId(int position) {
	  return position;
	 }

	 public View getView(int position, View convertView, ViewGroup parent) {
	  ViewEvent event;
	  if (convertView == null) {
	   convertView = mInflater.inflate(R.layout.list, null);
	   event = new ViewEvent();
	   event.eventID = (TextView ) convertView.findViewById(R.id.eventID);
	   event.eventName = (TextView) convertView.findViewById(R.id.eventName);
	   event.eventDate = (TextView) convertView.findViewById(R.id.eventDate);
	   convertView.setTag(event);
	  } else {
		  event = (ViewEvent) convertView.getTag();
	  }
	  
	  event.eventID.setText(eventList.get(position).getEventID());
	  event.eventName.setText(eventList.get(position).getEventName());
	  event.eventDate.setText(eventList.get(position).getEventDate());
	 
	  return convertView;
	 }

	 static class ViewEvent {
	  TextView eventID;
	  TextView eventName;
	  TextView eventDate;
	 }
	}
